package com.dayu.rabbitmq.ps;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.dayu.rabbitmq.util.MQUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * @author dayu
 * @date 2019/02/20
 * @Describe publish /subscribe 订阅模式,一个生产者发送给多个消费者
 */
public class Send {

    private static String EXCHANGE_NAME = "test_exchange_fanout";

    public static void main(String[] args) throws IOException, TimeoutException {

        Connection connection = MQUtil.getConnection();

        Channel channel = connection.createChannel();
        // 声明交换机
        channel.exchangeDeclare(EXCHANGE_NAME, "fanout");// 分发

        // 发送消息
        String msg = "hello exchagge!";
        channel.basicPublish(EXCHANGE_NAME, "", null, msg.getBytes());
        System.out.println(" send :" + msg);

        channel.close();
        connection.close();
    }
}
